//
//  UIButton+Extension.swift
//  Sina
//
//  Created by maling  on 15/11/3.
//  Copyright © 2015年 maling . All rights reserved.
//

import UIKit

extension UIButton {

  //‘遍历’构造函数--对撰写按钮懒加载 封装
    // - 备注： 如果图像名称使用 "" 会报错 CUICatalog: Invalid asset name supplied:
    convenience init(imageName: String, backImage: String?){
//    let btn = UIButton()
      
        self.init()
    setImage(UIImage(named: imageName), forState: UIControlState.Normal)
    setImage(UIImage(named: imageName + "_highlighted"), forState: UIControlState.Normal)
    
        if let backImageName = backImage {
    setBackgroundImage(UIImage(named: backImageName), forState:UIControlState.Normal)
    setBackgroundImage(UIImage(named: backImageName + "_highlighted"), forState:UIControlState.Highlighted)
        }
    sizeToFit()
        
    }
    
    /**
    
    

    */
    //-----给注册，登录按钮添加一个遍历构造函数
    convenience init(title: String, color: UIColor, imageName: String) {
    
//        let btn = UIButton()
        self.init()
       setTitle(title, forState: UIControlState.Normal)
        setTitleColor(color, forState: UIControlState.Normal)
       setBackgroundImage(UIImage(named:imageName ), forState: UIControlState.Normal)
        
        sizeToFit()
//        return btn
        
    }
    
   //遍历构造函数 -对cell的转发点赞 设置的
    convenience init(title: String, fontSize: CGFloat, color: UIColor, imageName: String) {
    
        self.init()
        setTitle(title, forState: .Normal)
        setTitleColor(color, forState: .Normal)
        setImage(UIImage(named: imageName), forState: .Normal)
        
        titleLabel?.font = UIFont.systemFontOfSize(fontSize)
        sizeToFit()
    }
    
}

    
    
    /*
    let btn = UIButton()
    btn.setTitle("注册", forState: UIControlState.Normal)
    btn.setTitleColor(UIColor.orangeColor(), forState: UIControlState.Normal)
    btn.setBackgroundImage(UIImage(named:"common_button_white_disable" ), forState: UIControlState.Normal)
    
    return btn

    */


